package com.magenta.maxoptra.gis.utils;

import com.magenta.maxoptra.gis.GeoProviderSettings;

import java.util.Date;

import static com.magenta.maxoptra.gis.GisParameter.cacheStorageTime;

/**
 * @author Sergey Grachev
 */
public final class GeoProviderSettingsUtils {
    private GeoProviderSettingsUtils() {
    }

    public static boolean isExpiredCacheEntry(final String cacheStorageTime, final Long time) {
        int cacheStorageTimeInDays = 100000;
        if (cacheStorageTime != null) {
            cacheStorageTimeInDays = Integer.parseInt(cacheStorageTime);
        }
        Date currentTime = TimeZoneUtils.getServerCurrentTime();

        return (currentTime.getTime() - time) > cacheStorageTimeInDays * DateTimeHelper.MSECS_IN_DAY;
    }

    public static boolean isExpiredCacheEntry(final GeoProviderSettings settings, final Long time) {
        return isExpiredCacheEntry(settings.getGisParam(cacheStorageTime.withProvider(settings.getProviderName())), time);
    }
}
